<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <my-grandfather></my-grandfather>
    </div>

    <!-- 爷爷组件 -->
    <template id="grandfather">
        <div>
            <h1>
                我是爷爷组件 --
            </h1>
            <button @click="rem">销毁</button>
            <my-father v-if="flag"></my-father>
        </div>
    </template>


    <!-- 父组件 -->
    <template id="father">
        <div>
            <h3>
                我是父组件
            </h3>
        </div>
    </template>

    <script src="./vue.js"></script>
    <script>

        // 父组件 
        const Father = {
            template: "#father",
            data() {
                return {
                    timer: null
                }
            },
            mounted() {
                this.timer = setInterval(() => {
                    console.log(1)
                }, 1000);
            },
            beforeDestroy() {
                console.log("我要销毁了")
                clearInterval(this.timer)
            },
            destroyed() {
                console.log('销毁完毕')
            }
        }


        // 爷爷组件 
        const GrandFather = {
            template: "#grandfather",
            components: {
                "my-father": Father
            },
            data() {
                return {
                    flag: true
                }
            },
            methods: {
                rem() {
                    this.flag = false
                }
            }
        }

        new Vue({
            el: "#app",
            components: {
                "my-grandfather": GrandFather
            }
        })
    </script>
</body>

</html>